########################## Autor PiJey77@mail.com 
import BigWorld
import cPickle
import GUI
import json
import os
import csv
import codecs
import ResMgr
import math
import re
import game
import Keys
import string
import constants
import datetime
import time
import nations
from items import vehicles as vehiclesWG
from copy import copy
from CurrentVehicle import g_currentVehicle
from constants import ITEM_DEFS_PATH
from messenger.m_constants import BATTLE_CHANNEL
from ChatManager import chatManager
from gui.WindowsManager import g_windowsManager
from Avatar import PlayerAvatar
from ClientArena import ClientArena
from gui import g_guiResetters
from collections import defaultdict
from gui.Scaleform.Battle import Battle, VehicleMarkersManager
from gui.BattleContext import g_battleContext
from VehicleEffects import DamageFromShotDecoder
from messenger import MessengerEntry
from items import _xml, vehicles
from Vehicle import Vehicle
from debug_utils import *

ATTACK_REASONS = [
    'Shot',
    'Fire',
    'Ram',
    'Fall',
    'Expl',
    'Drown']
HIT_EFFECT = [
    'RICOCHET',
    'ARMOR_NOT_PIERCED',
    'ARMOR_PIERCED_NO_DAMAGE',
    'ARMOR_PIERCED',
    'CRITICAL_HIT',
    'MAX_CODE']
LOG_LEVEL = [
    'DEBUG',
    'INFO',
    'WARNING',
    'ERROR']


class MultiHitLog(object):
    
    myConfig = defaultdict(dict)
    myConfigKey = defaultdict(dict)
    myWindowKeyList = defaultdict(dict)
    myConfigCopy = defaultdict(dict)
    myFont = defaultdict(dict)
    myWindows = None
    myWindowsKey = defaultdict(myWindows)
    myConfigFileName = ''
    myConfigOK = True
    myCsvOK = True
    myVisibleFlag = True

    myTankExpDArray = defaultdict(dict)
    myTankListAlly = defaultdict(dict)
    myTankListEnemy = defaultdict(dict)
    myTankListEnemySorted = defaultdict(dict)
    myTankListDescr = defaultdict(dict)
    myTargetedTankDescr = defaultdict(dict)

    myWindowLabelsKey = defaultdict(dict)
    myLineTypesOrig = defaultdict(dict)
    myLineTypesKey = defaultdict(dict)
   
    myColors = defaultdict(dict)
    myHPLeft = defaultdict(dict)
    myDamageLog = defaultdict(dict)
    myHitLogList = defaultdict(dict)
    myDamageLogList = defaultdict(dict)
    
    myTankCounterAlly = 1
    myTankCounterEnemy = 1
    myHitLogCounter = 0
    myHitsCounter = 0
    myDamageLogCounter = 0
    myDamageLineCounter = 0
    myTypeDescriptor = 0
    myFloatingCounter = 0
    myTotalDamage = 0
    myLastTime = 0
    myLastTime2 = 0
    myIPtimer = 0
    myCritic = 0
    
    myHitLogTime = 1
    myHitLogSwitch = False
    myDamageLogTime = 1
    myDamageLogSwitch = False
    myInfoPanelTime = 1
    myInfoPanelSwitch = False
    myIsNewDamage = False
    
    myHits = 0
    myExpDamage = 0
    myWN8 = 0
    myEFF = 0
    myXWN8 = 0
    myXEFF = 0
    myHitType = 0
    myError = 'Error'
    myAvgDamage = 0
    myCurrDamage = 0
    myFrags = 0
    myLastDamage = 0
    myLastAttacker = 0
    myIsItLast = 0
    myFirstTarget = False
    myPen = 0
    myBounce = 0
    myAlly = 0
    myHitLogPozz = 0
    myTimer = {}
    myTotalDamageReceived = 0
    myTotalLabels = 0
    myLineMultipler = 1.4

    def __init__(self):                  
        res = ResMgr.openSection('../paths.xml')
        sb = res['Paths']
        vals = sb.values()[0:2]
        
        xmlFile = ResMgr.openSection('scripts/client/mods/MultiHitLog/Config_File_Chooser.xml')
        self.myConfigFileName = xmlFile.readString('ConfigFileName')
        print '                                             MultiHitLog v.1.5 by PiJey77 and mtm78'
        print '                                             MultiHitLog: Config file used:' + self.myConfigFileName

        for vl in vals:
            path = vl.asString + '/scripts/client/mods/MultiHitLog/'
            if os.path.isdir(path):
                conf_file = path + self.myConfigFileName
                if os.path.isfile(conf_file):
                    try:
                        json_data = open(conf_file)
                        self.myConfig = json.load(json_data)
                        json_data.close()
                        json_data = open(conf_file)
                        self.myConfigCopy = json.load(json_data)
                        json_data.close()
                    except ValueError:
                        self.myConfigOK = False
                        print 'MultiHitLog: error in json file'
        for vl in vals:
            path = vl.asString + '/scripts/client/mods/MultiHitLog/'
            if os.path.isdir(path):
                expectedValuesPath = path + 'TankData.csv'
                if os.path.isfile(expectedValuesPath):
                    try:
                        self.myTankExpDArray = list( csv.reader( codecs.open( expectedValuesPath , encoding='cp1250') ) )
                    except ValueError:
                        self.myCsvOK = False
                else:
                    self.myCsvOK = False
        self.myLastTime = time.time()
        self.myLastTime2 = time.time()
        self.myIPtimer = time.time()

    def resetData(self):
        res = ResMgr.openSection('../paths.xml')
        sb = res['Paths']
        vals = sb.values()[0:2]        
        xmlFile = ResMgr.openSection('scripts/client/mods/MultiHitLog/Config_File_Chooser.xml')
        self.myConfigFileName = xmlFile.readString('ConfigFileName')
        for vl in vals:
            path = vl.asString + '/scripts/client/mods/MultiHitLog/'
            if os.path.isdir(path):
                conf_file = path + self.myConfigFileName
                if os.path.isfile(conf_file):
                    try:
                        json_data = open(conf_file)
                        self.myConfig = json.load(json_data)
                        json_data.close()
                        json_data = open(conf_file)
                        self.myConfigCopy = json.load(json_data)
                        json_data.close()
                        print 'MultiHitLog: Config reloaded, all data has been reset'
                    except ValueError:
                        self.myConfigOK = False
                        print 'MultiHitLog: error in json file'
        self.myVisibleFlag = True
        self.myTankListAlly = defaultdict(dict)
        self.myTankListEnemy = defaultdict(dict)
        self.myTankListEnemySorted = defaultdict(dict)
        self.myHitLogList = defaultdict(dict)
        self.myDamageLogList = defaultdict(dict)    
        self.myTankCounterAlly = 1
        self.myTankCounterEnemy = 1
        self.myTotalDamage = 0
        self.myLastTime = 0
        self.myIsNewDamage = False
        self.myFloatingCounter = 0
        self.myLastDamage = 0
        self.myHits = 0
        self.myFirstTarget = False
        self.myExpDamage = 0
        self.myWN8 = 0
        self.myEFF = 0
        self.myXWN8 = 0
        self.myXEFF = 0
        self.myHitLogCounter = 0
        self.myHitsCounter = 0
        self.myError = 'Error'
        self.myAvgDamage = 0
        self.myCurrDamage = 0
        self.myFrags = 0
        self.myLastAttacker = 0
        self.myHitType = 0
        self.myPen = 0
        self.myBounce = 0
        self.myAlly = 0
        self.myDamageLineCounter = 0
        self.myHitLogPozz = 0
        self.myTimer = {}
        self.myTotalDamageReceived = 0
        self.myIsItLast = 0
        self.myDamageLogCounter = 0

    @staticmethod
    def hexToRgba(hex):
        try:
            rgba = [int(hex[i:i+2], 16) for i in range(1,6,2)]
            rgba.append(255)
            return tuple(rgba)
        except:
            print str(hex) + " - Unexpected error:" + str(hex)
            hex = '#000000'
            rgba = [int(hex[i:i+2], 16) for i in range(1,6,2)]
            rgba.append(255)
            return tuple(rgba)

    def onChangeScreenResolution(self):
        for z in xrange(0,len(self.myWindowKeyList)):   
            sr = GUI.screenResolution()
            w = self.checkWidth(z)
            h = self.checkHeight(z)
            y = self.myWindowKeyList[z]['y']  
            x = self.myWindowKeyList[z]['x']            
            if self.myWindowKeyList[z]['xAlign'] == 'Center':
                x = (sr[0] / 2) - (w / 2) + x
            else:
                if x < 0:
                    x = sr[0] + x - w
            if self.myWindowKeyList[z]['yAlign'] == 'Center':
                y = (sr[1] / 2) - (h / 4) + y
            else:
                if y < 0:
                    y = sr[1] + y - h
            self.myWindowsKey[z].position = (x, y, 1)

    def insertLabel(self, item, x, y, size, window):
        item.font = self.myFont[size]['font']
        window.addChild(item)
        item.widthMode = item.heightMode = item.verticalPositionMode = item.horizontalPositionMode = 'PIXEL'
        item.horizontalAnchor = 'LEFT'
        item.verticalAnchor = 'TOP'
        item.colour = (200, 200, 200, 255)
        item.multiline = True
        item.visible = True
        item.position = (x, y, 1)

    def loadConfigData(self):
        self.myWindowKeyList = self.myConfig.get('WindowKeyList')
        
        for z in xrange(0,len(self.myWindowKeyList)):
            self.myConfigKey[z] = self.myConfig.get(self.myWindowKeyList[z]['ConfigName'])
            
        self.myColors = self.myConfig.get('Colors')
        self.myFont = self.myConfig.get('Fonts')

        for z in xrange(0,101):
            myType = 'Type' + str(z)
            self.myLineTypesOrig[z] = self.myConfig.get(myType)

        for z in xrange(0,len(self.myWindowKeyList)):
            for z1 in xrange(0,len(self.myConfigKey[z])):
                lineNr = self.checkLine(self.myConfigKey[z][z1]['LineType'])
                self.myLineTypesKey[z][z1] = self.myConfigCopy.get(self.myConfigKey[z][z1]['LineType'])
                for z2 in xrange(0,len(self.myLineTypesOrig[lineNr])):
                    self.myLineTypesKey[z][z1][z2]['text'] = ''
                    self.myLineTypesKey[z][z1][z2]['color'] = self.hexToRgba('#000000')
                    self.myTotalLabels += 1

    def checkHeight(self, z):
        return len(self.myConfigKey[z]) * self.myFont[0]['height'] * self.myLineMultipler

    def checkWidth(self, z):
        biggestWidth = 0
        if self.myWindowKeyList[z]['width'] == 0:
            for x in xrange(0,len(self.myConfigKey[z])):
                width = 0
                if self.myConfigKey[z][x]['LineType'] <> 'Type1' and self.myConfigKey[z][x]['LineType'] <> 'Type0':
                    LineType = self.myConfig.get(self.myConfigKey[z][x]['LineType'])
                    for y in xrange(0,len(LineType)):
                        if LineType[y]['width'] != 'Center':
                            width += (LineType[y]['width'] * self.myFont[LineType[y]['size']]['width'])
                    if biggestWidth < width: biggestWidth = width
            return biggestWidth
        if self.myWindowKeyList[z]['width'] != 0:
            return self.myWindowKeyList[z]['width']

    def checkBackground(self, level, ownFile):
        background =  ''
        if level == -1:
            background = os.path.join('scripts', 'client', 'mods', 'MultiHitLog', ownFile)
        if level == 0: background = ''
        elif level == 1: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround1.dds')
        elif level == 2: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround2.dds')
        elif level == 3: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround3.dds')
        elif level == 4: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround4.dds')
        elif level == 5: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround5.dds')
        elif level == 6: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround6.dds')
        elif level == 7: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround7.dds')
        elif level == 8: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround8.dds')
        elif level == 9: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround9.dds')
        elif level == 10: background =  os.path.join('scripts', 'client', 'mods', 'MultiHitLog', 'BackGround10.dds')
        return background

    def createWindows(self):       
        if self.myConfigOK != True:
            print 'MultiHitLog error in json file.'        
            return        
        self.loadConfigData()
        g_guiResetters.add(self.onChangeScreenResolution)         
        for z in xrange(0,len(self.myWindowKeyList)):    
            background = self.checkBackground(self.myWindowKeyList[z]['backgroundLevel'],self.myWindowKeyList[z]['backgroundFile'])
            self.myWindowsKey[z] = GUI.Window(background)        
            self.myWindowsKey[z].colour = (255, 255, 255, 255)
            self.myWindowsKey[z].materialFX = "BLEND"
            self.myWindowsKey[z].verticalAnchor = "TOP"
            self.myWindowsKey[z].horizontalAnchor = "LEFT"
            self.myWindowsKey[z].verticalPositionMode = self.myWindowsKey[z].heightMode = self.myWindowsKey[z].widthMode = self.myWindowsKey[z].horizontalPositionMode = 'PIXEL'
            self.myWindowsKey[z].width = self.checkWidth(z)
            self.myWindowsKey[z].height = self.checkHeight(z)
            GUI.addRoot(self.myWindowsKey[z])        
        self.onChangeScreenResolution()

    def createLabels(self):
        if self.myConfigOK != True:
            print 'MultiHitLog error in json file.'        
            return
        for z in xrange(0,len(self.myWindowKeyList)):
            y = self.myWindowKeyList[z]['offsetY']
            for z1 in xrange(0,len(self.myConfigKey[z])):
                x = self.myWindowKeyList[z]['offsetX']
                y = z1 * self.myFont[0]['height'] * self.myLineMultipler
                lineNr = self.checkLine(self.myConfigKey[z][z1]['LineType'])        
                for z2 in xrange(0,len(self.myLineTypesOrig[lineNr])):
                    unIdTxt = '1' + str(z)+str(z1)+str(z2)
                    unId = int(unIdTxt)
                    FontSize = self.myLineTypesOrig[lineNr][z2]['size']
                    if self.myLineTypesOrig[lineNr][z2]['width'] == 'Center':
                        x = (self.checkWidth(z) / 2) - ((len(self.myLineTypesOrig[lineNr][z2]['text']) * self.myFont[FontSize]['width']) /2)                    
                    self.myWindowLabelsKey[unId] = GUI.Text('')
                    self.insertLabel(self.myWindowLabelsKey[unId], x, y, FontSize , self.myWindowsKey[z])                
                    if self.myLineTypesOrig[lineNr][z2]['width'] != 'Center':
                        KeyWidth = self.myLineTypesOrig[lineNr][z2]['width']
                        x += KeyWidth * (self.myFont[FontSize]['width'])

    def keyPressed(self, text):
        if self.myDamageLogSwitch == True:
            self.myInfoPanelSwitch = False
            self.myInfoPanelTime = 0
            self.myHitLogSwitch = False
            self.myHitLogTime = 0
            
        elif self.myInfoPanelSwitch == True:
            self.myHitLogSwitch = False
            self.myHitLogTime = 0
            self.myDamageLogSwitch = False
            self.myDamageLogTime = 0
            
        elif self.myHitLogSwitch == True:
            self.myDamageLogSwitch = False
            self.myDamageLogTime = 0
            self.myInfoPanelSwitch = False
            self.myInfoPanelTime = 0
            
        for z in xrange(0,len(self.myWindowKeyList)):
            if self.myWindowKeyList[z]['Key'] == "HitLog" and self.myHitLogSwitch == True:
                self.myHitLogTime = time.time()
                self.myHitLogSwitch = False
                try: self.myWindowsKey[z].visible = self.myVisibleFlag
                except: pass
            
            if self.myWindowKeyList[z]['Key'] == "HitLog" and self.myHitLogSwitch == False:
                if (time.time() - self.myWindowKeyList[z]['time']) > self.myHitLogTime or self.myHitLogTime == 0:
                    try: self.myWindowsKey[z].visible = False
                    except: pass
                else:
                    for z2 in xrange(0,len(self.myWindowKeyList)):
                        if z <> z2:
                            if self.myWindowKeyList[z2]['xAlign'] == self.myWindowKeyList[z]['xAlign']:
                                if self.myWindowKeyList[z2]['yAlign'] == self.myWindowKeyList[z]['yAlign']:
                                    if self.myWindowKeyList[z2]['x'] == self.myWindowKeyList[z]['x']:
                                        if self.myWindowKeyList[z2]['y'] == self.myWindowKeyList[z]['y']:
                                           try: self.myWindowsKey[z2].visible = False
                                           except: pass

            if self.myWindowKeyList[z]['Key'] == "DamageLog" and self.myDamageLogSwitch == True:
                self.myDamageLogTime = time.time()
                self.myDamageLogSwitch = False
                try: self.myWindowsKey[z].visible = self.myVisibleFlag
                except: pass
                
            if self.myWindowKeyList[z]['Key'] == "DamageLog" and self.myDamageLogSwitch == False:
                if (time.time() - self.myWindowKeyList[z]['time']) > self.myDamageLogTime or self.myDamageLogTime == 0:
                    try: self.myWindowsKey[z].visible = False
                    except: pass
                else:
                    for z2 in xrange(0,len(self.myWindowKeyList)):
                        if z <> z2:
                            if self.myWindowKeyList[z2]['xAlign'] == self.myWindowKeyList[z]['xAlign']:
                                if self.myWindowKeyList[z2]['yAlign'] == self.myWindowKeyList[z]['yAlign']:
                                    if self.myWindowKeyList[z2]['x'] == self.myWindowKeyList[z]['x']:
                                        if self.myWindowKeyList[z2]['y'] == self.myWindowKeyList[z]['y']:
                                           try: self.myWindowsKey[z2].visible = False
                                           except: pass

            if self.myWindowKeyList[z]['Key'] == "InfoPanel" and self.myInfoPanelSwitch == True:
                self.myInfoPanelTime = time.time()
                self.myInfoPanelSwitch = False
                try: self.myWindowsKey[z].visible = self.myVisibleFlag
                except: pass
                
            if self.myWindowKeyList[z]['Key'] == "InfoPanel" and self.myInfoPanelSwitch == False:
                if (time.time() - self.myWindowKeyList[z]['time']) > self.myInfoPanelTime or self.myInfoPanelTime == 0:
                    try: self.myWindowsKey[z].visible = False
                    except: pass
                else:
                    for z2 in xrange(0,len(self.myWindowKeyList)):
                        if z <> z2:
                            if self.myWindowKeyList[z2]['xAlign'] == self.myWindowKeyList[z]['xAlign']:
                                if self.myWindowKeyList[z2]['yAlign'] == self.myWindowKeyList[z]['yAlign']:
                                    if self.myWindowKeyList[z2]['x'] == self.myWindowKeyList[z]['x']:
                                        if self.myWindowKeyList[z2]['y'] == self.myWindowKeyList[z]['y']:
                                           try: self.myWindowsKey[z2].visible = False
                                           except: pass
                                           
        for z in xrange(0,len(self.myWindowKeyList)):
            if self.myWindowKeyList[z]['Key'] != 'HitLog' and self.myWindowKeyList[z]['Key'] != 'DamageLog' and self.myWindowKeyList[z]['Key'] != 'InfoPanel':
                try: self.myWindowsKey[z].visible = False
                except: pass
                
        found = False
        for z in xrange(0,len(self.myWindowKeyList)):
            if self.myWindowKeyList[z]['Key'] == text:
                found = True
                try: self.myWindowsKey[z].visible = self.myVisibleFlag
                except: pass
                
                for z2 in xrange(0,len(self.myWindowKeyList)):
                    if z <> z2:
                        if self.myWindowKeyList[z2]['xAlign'] == self.myWindowKeyList[z]['xAlign']:
                            if self.myWindowKeyList[z2]['yAlign'] == self.myWindowKeyList[z]['yAlign']:
                                if self.myWindowKeyList[z2]['x'] == self.myWindowKeyList[z]['x']:
                                    if self.myWindowKeyList[z2]['y'] == self.myWindowKeyList[z]['y']:
                                        try: self.myWindowsKey[z2].visible = False
                                        except: pass
        for z in xrange(0,len(self.myWindowKeyList)):                
            if found == False and self.myWindowKeyList[z]['Key'] == 'NONE':
                try: self.myWindowsKey[z].visible = self.myVisibleFlag
                except: pass              
            if self.myWindowKeyList[z]['Key'] == 'ALWAYS':
                try: self.myWindowsKey[z].visible = self.myVisibleFlag
                except: pass
        return

    def PassTypeDescr(self, typeDescriptor):
        self.myTypeDescriptor = typeDescriptor

    def setVisible(self, flag):
        self.myVisibleFlag = flag
        for z in xrange(0,len(self.myWindowKeyList)):
            self.myWindowsKey[z].visible = flag

    def deleteWindow(self):
        for z in xrange(0,len(self.myWindowKeyList)):
            GUI.delRoot(self.myWindowsKey[z])
            self.myWindowsKey[z] = None

    def CheckBattleType(self):
        player = BigWorld.player()
        battleType = player.arena.guiType
        battleTypeName = ''
        if battleType == constants.ARENA_GUI_TYPE.RANDOM:
            battleTypeName = 'Random'
        elif battleType == constants.ARENA_GUI_TYPE.TRAINING:
            battleTypeName = 'Training'
        elif battleType == constants.ARENA_GUI_TYPE.COMPANY:
            battleTypeName = 'Company'
        elif battleType == constants.ARENA_GUI_TYPE.CYBERSPORT:
            battleTypeName = 'CyberSport'
        else:
            battleTypeName = 'ClanWar'
        return battleTypeName

    def calcEFI(self, xDamage, expectedDamage, rSPOT, rFRAG, frags, rDEF, rWIN, rTIER):
        rDAMAGE = float(xDamage) / float(expectedDamage)
        rSPOT = 0 / float(rSPOT)
        rFRAG = float(frags) / float(rFRAG)
        rDEF = 0 / float(rDEF)
        rWIN = 0 / float(rWIN)
        rWINc = max(0, int(rWIN) - 0.71/(1 - 0.71))
                
        rDAMAGEc = max(0, (rDAMAGE - 0.22)/(1 - 0.22))
        rFRAGc = max(0, min(rDAMAGEc + 0.2, (rFRAG - 0.12)/(1 - 0.12)))
        rSPOTc = max(0, min(rDAMAGEc + 0.1, (rSPOT - 0.38)/(1 - 0.38)))
        rDEFc = max(0, min(rDAMAGEc + 0.1, (rDEF - 0.10)/(1 - 0.10)))              
        WN8 = 980*rDAMAGEc + 210*rDAMAGEc*rFRAGc + 155*rFRAGc*rSPOTc + 75*rDEFc*rFRAGc + 145*min(1.8, rWINc)

        avgDamage = float(xDamage)
        avgFrag = float(frags)
        avgSpot = float(rSPOT)
        avgDef = float(rDEF)
        avgCap = float(0)
        avgTier = float(rTIER)
        EFF = max(0, int(avgDamage*(10/(avgTier + 2)) * (0.23 + 2*avgTier/100) + avgFrag * 250 + avgSpot *\
                150 + math.log(avgCap + 1, 1.732) * 150 + avgDef * 150))

        if WN8 > 3250:
            XWN8 = 100
        else:
            pass
            XWN8 = 0
            XWN8 = int(max(min(WN8 * (WN8 * (WN8 * (WN8 * (WN8 * (0.000000000000000000071 * WN8 + 0.0000000000000002455) - 0.000000000006785) + 0.00000002708) - 0.000042707) + 0.06319) + 0.348, 100), 0))

        if EFF < 350:
            EFF = 0
            XEFF = 0
        else:
            XEFF = int(max(min(EFF * ( EFF * (EFF * (EFF * (EFF * (0.00000000000000003388 * EFF - 0.0000000000002469) + 0.00000000069335) - 0.00000095342) + 0.0006656) -0.1485) - 0.85, 100), 0))
        
        return int(WN8), int(EFF), int(XWN8), int(XEFF)

    def checkMacros(self, text, battleID, HLPozz, attackReasonID, attackerID = 0, Damage = 0, effectsIndex = 0, place = '', Width = 0, hitNr = -1):
        try:
            player = BigWorld.player()
            current = player.arena.vehicles.get(battleID)
            attacker = player.arena.vehicles.get(attackerID)
            currentVehicleID = player.playerVehicleID
        except:
            pass
        
        attackerAmmo = 'credit'
        attackerShellType = ''
        
        try:
            for shell in attacker['vehicleType'].gun['shots']:
                if effectsIndex == shell['shell']['effectsIndex']:
                    price = self.getShellPrice(shell['shell']['id'][0], shell['shell']['id'][1])
                    if price[1] != 0:
                        attackerAmmo = 'gold'
                    else:
                        attackerAmmo = 'credit'
                        
                    if shell['shell']['kind'] == 'ARMOR_PIERCING':
                        attackerShellType = self.myConfig.get('AP_Shell')

                    if shell['shell']['kind'] == 'ARMOR_PIERCING_CR':
                        attackerShellType = self.myConfig.get('APCR_Shell')

                    if shell['shell']['kind'] == 'ARMOR_PIERCING' and  attackerAmmo == 'gold':
                        attackerShellType = self.myConfig.get('APCR_G_Shell')
                        
                    if shell['shell']['kind'] == 'HIGH_EXPLOSIVE' and  attackerAmmo == 'credit':
                        attackerShellType = self.myConfig.get('HE_Shell')
                        
                    if shell['shell']['kind'] == 'HIGH_EXPLOSIVE' and  attackerAmmo == 'gold':
                        attackerShellType = self.myConfig.get('HESH_G_Shell')

                    if shell['shell']['kind'] == 'HOLLOW_CHARGE':
                        attackerShellType = self.myConfig.get('HEAT_G_Shell')
                    break
        finally:
            pass

        if '{{DL_HitNr}}' in text:
            textX = str(hitNr).zfill(2)
            text = text.replace('{{DL_HitNr}}',textX)

        if '{{DL_AttackerDamage}}' in text:
            textX = str(Damage)
            text = text.replace('{{DL_AttackerDamage}}',textX)

        if '{{DL_AttackerAmmo}}' in text:
            textX = str(attackerShellType)            
            text = text.replace('{{DL_AttackerAmmo}}',textX)   
            
        if '{{DL_AttackType}}' in text:
            textX = str(ATTACK_REASONS[attackReasonID])            
            text = text.replace('{{DL_AttackType}}',textX)         

        if '{{DL_AttackerTank}}' in text:
            textX = str(unicode(attacker['vehicleType'].type.shortUserString, 'utf-8'))
            if Width > 0:
                textX = textX[0:Width]
                text = text.replace('{{DL_AttackerTank}}',textX)

        if '{{DL_AttackerName}}' in text:
            textX = str(attacker['name'])
            if Width > 0:
                textX = textX[0:Width]
            text = text.replace('{{DL_AttackerName}}',textX)

        if '{{DL_AttackerPlace}}' in text:
            textX = str(place)
            text = text.replace('{{DL_AttackerPlace}}',textX)

        if '{{DL_AttackerReload}}' in text:            
            def isOptionalEquipped(vehicle, optional_name):
                for item in vehicle.optionalDevices:
                    if item is not None and optional_name in item.name:
                        return True
                return False
            loader_skill = 126.5
            if isOptionalEquipped(attacker['vehicleType'], 'improvedVentilation'):
                loader_skill = 132.0
            other_bonus = 1.0
            if isOptionalEquipped(attacker['vehicleType'], 'TankRammer'):
                other_bonus *= 0.9                        
            reloadTime = attacker['vehicleType'].gun['reloadTime']
            reloadTime = reloadTime * 0.875 / (0.00375 * loader_skill + 0.5) * other_bonus
            reloadTimeText = "{:.2f}".format(reloadTime)
            textX = reloadTimeText + 's'
            text = text.replace('{{DL_AttackerReload}}',textX)
        
        if '{{HL_DMG}}' in text:
            text = text.replace('{{HL_DMG}}',str(self.myTotalDamage))
        if '{{HL_WN8}}' in text:
            text = text.replace('{{HL_WN8}}',str(int(self.myWN8)))
        if '{{HL_EFF}}' in text:
            text = text.replace('{{HL_EFF}}',str(int(self.myEFF)))
        if '{{HL_XWN8}}' in text:
            text = text.replace('{{HL_XWN8}}',str(int(self.myXWN8)))
        if '{{HL_XEFF}}' in text:
            text = text.replace('{{HL_XEFF}}',str(int(self.myXEFF)))
        if '{{HL_Diff}}' in text:
            text = text.replace('{{HL_Diff}}',str(int(self.myCurrDamage)))
        if '{{HL_Shots}}' in text:
            text = text.replace('{{HL_Shots}}',str(int(self.myHits)))
        if '{{HL_AvgDMG}}' in text:
            text = text.replace('{{HL_AvgDMG}}',str(int(self.myAvgDamage)))
        if '{{HL_LastDMG}}' in text:
            text = text.replace('{{HL_LastDMG}}',str(int(self.myLastDamage)))
        if '{{DL_TotalPen}}' in text:
            text = text.replace('{{DL_TotalPen}}',str(int(self.myPen)))
        if '{{DL_TotalBounce}}' in text:
            text = text.replace('{{DL_TotalBounce}}',str(int(self.myBounce)))
        if '{{DL_TotalAlly}}' in text:
            text = text.replace('{{DL_TotalAlly}}',str(int(self.myAlly)))
        if '{{DL_ReceivedHits}}' in text:
            received_hits = int(self.myPen) + int(self.myBounce) + int(self.myAlly)
            text = text.replace('{{DL_ReceivedHits}}', str(received_hits))
        if '{{DL_TotalReceived}}' in text:
            text = text.replace('{{DL_TotalReceived}}', str(self.myTotalDamageReceived))
        
        if '{{HL_Hits}}' in text and HLPozz >=0:
            text = text.replace('{{HL_Hits}}',str(int(self.myHitLogList[HLPozz]['Hits'])))
        elif '{{HL_Hits}}' in text and HLPozz < 0:
            text = ''
            
        if '{{HL_TotalDamage}}' in text and HLPozz >=0:
            text = text.replace('{{HL_TotalDamage}}',str(int(self.myHitLogList[HLPozz]['TotalDamage'])))
        elif '{{HL_TotalDamage}}' in text and HLPozz < 0:
            text = ''
            
        if '{{HL_LastDamage}}' in text and HLPozz >=0:
            text = text.replace('{{HL_LastDamage}}',str(int(self.myHitLogList[HLPozz]['LastDamage'])))
        elif '{{HL_LastDamage}}' in text and HLPozz < 0:
            text = ''
            
        if '{{HL_Tank}}' in text and HLPozz >=0:
            textX = str(self.myHitLogList[HLPozz]['Tank'])
            if Width > 0:
                textX = textX[0:Width]
            text = text.replace('{{HL_Tank}}',textX)                
        elif '{{HL_Tank}}' in text and HLPozz < 0:
            text = ''

        if '{{HL_Name}}' in text and HLPozz >=0:
            textX = str(self.myHitLogList[HLPozz]['Name'])
            if Width > 0:
                textX = textX[0:Width]
            text = text.replace('{{HL_Name}}',textX)
        elif '{{HL_Name}}' in text and HLPozz < 0:
            text = ''
            
        if '{{HL_Killed}}' in text and HLPozz >=0:
            if self.myHitLogList[HLPozz]['Killed'] == 'False':
                text = text.replace('{{HL_Killed}}','')
            if self.myHitLogList[HLPozz]['Killed'] == 'True':
                text = text.replace('{{HL_Killed}}',self.myConfig.get('HL_Killed_Text'))
        elif '{{HL_Killed}}' in text and HLPozz < 0:
            text = ''

        if '{{HL_Ally}}' in text and HLPozz >=0:
            if self.myHitLogList[HLPozz]['Ally'] == 'False':
                text = text.replace('{{HL_Ally}}','')
            if self.myHitLogList[HLPozz]['Ally'] == 'True':
                text = text.replace('{{HL_Ally}}',self.myConfig.get('HL_Ally_Text'))
        elif '{{HL_Ally}}' in text and HLPozz < 0:
            text = ''
        
        if '{{HL_AttackType}}' in text and HLPozz >= 0:
            text = text.replace('{{HL_AttackType}}',str(ATTACK_REASONS[self.myHitLogList[HLPozz]['Attack']]))
        elif '{{HL_AttackType}}' in text and HLPozz < 0:
            text = ''

        if '{{DL_AttackType}}' in text:
            try:    text = text.replace('{{DL_AttackType}}',str(ATTACK_REASONS[attackReasonID]))
            except: text = ''          
        if '{{HP_EnemyTank}}' in text:
            try:    text = text.replace('{{HP_EnemyTank}}',str(self.myTankListEnemySorted[HLPozz]['tankName']))
            except: text = ''
        if '{{HP_EnemyName}}' in text:
            try:    text = text.replace('{{HP_EnemyName}}',str(self.myTankListEnemySorted[HLPozz]['playerName']))
            except: text = ''
        if '{{HP}}' in text:
            try:    text = text.replace('{{HP}}',str(int(self.myTankListEnemySorted[HLPozz]['maxHealth'])))
            except: text = ''
        if '{{HP_Left}}' in text:
            try:    text = text.replace('{{HP_Left}}',str(int(self.myTankListEnemySorted[HLPozz]['currentHealth'])))
            except: text = ''
            
            
            
        if '{{IP_Tank}}' in text:
            textX = str(self.myTargetedTankDescr['TankName'])
            if Width > 0:
                textX = textX[0:Width]
            try:    text = text.replace('{{IP_Tank}}',textX)
            except: pass        
        if '{{IP_Reload}}' in text:
            reloadTime = float(self.myTargetedTankDescr.get('ReloadTime') or 0)
            reloadTimeText = "{:.2f}".format(reloadTime)
            try:    text = text.replace('{{IP_Reload}}',reloadTimeText)
            except: pass
        if '{{IP_Gun}}' in text:
            textX = str(self.myTargetedTankDescr['gunName'])
            if Width > 0:
                textX = textX[0:Width]
            try:    text = text.replace('{{IP_Gun}}',textX)
            except: pass
        if '{{IP_ViewRange}}' in text:
            try:    text = text.replace('{{IP_ViewRange}}',str(self.myTargetedTankDescr['ViewRange']))
            except: pass
            
        if '{{IP_TargetWeight}}' in text:
            vWeight = self.myTargetedTankDescr.get('vWeight')
            try:    text = text.replace('{{IP_TargetWeight}}',str(vWeight))
            except: pass

        if '{{IP_MyWeight}}' in text:
            pWeight = self.myTargetedTankDescr.get('pWeight')
            try:    text = text.replace('{{IP_MyWeight}}',str(pWeight))
            except: pass

        if '{{IP_WeightDiff}}' in text:
            pWeight = self.myTargetedTankDescr.get('pWeight')
            vWeight = self.myTargetedTankDescr.get('vWeight')
            weight = int(pWeight or 0) - int(vWeight or 0)
            try:    text = text.replace('{{IP_WeightDiff}}',str(weight))
            except: pass
            
        if '{{IP_AmmoType1}}' in text:
            try:    text = text.replace('{{IP_AmmoType1}}',str(self.myTargetedTankDescr['shellType'][0]))
            except: pass
        if '{{IP_AmmoType2}}' in text:
            try:    text = text.replace('{{IP_AmmoType2}}',str(self.myTargetedTankDescr['shellType'][1]))
            except: pass
        if '{{IP_AmmoType3}}' in text:
            try:    text = text.replace('{{IP_AmmoType3}}',str(self.myTargetedTankDescr['shellType'][2]))
            except: pass
            
            
        if '{{IP_AmmoPen1}}' in text:
            try:    text = text.replace('{{IP_AmmoPen1}}',str(self.myTargetedTankDescr['shellPower'][0]))
            except: pass
        if '{{IP_AmmoPen2}}' in text:
            try:    text = text.replace('{{IP_AmmoPen2}}',str(self.myTargetedTankDescr['shellPower'][1]))
            except: pass
        if '{{IP_AmmoPen3}}' in text:
            try:    text = text.replace('{{IP_AmmoPen3}}',str(self.myTargetedTankDescr['shellPower'][2]))
            except: pass

        if '{{IP_AmmoDamage1}}' in text:
            try:    text = text.replace('{{IP_AmmoDamage1}}',str(self.myTargetedTankDescr['shellDamage'][0]))
            except: pass
        if '{{IP_AmmoDamage2}}' in text:
            try:    text = text.replace('{{IP_AmmoDamage2}}',str(self.myTargetedTankDescr['shellDamage'][1]))
            except: pass
        if '{{IP_AmmoDamage3}}' in text:
            try:    text = text.replace('{{IP_AmmoDamage3}}',str(self.myTargetedTankDescr['shellDamage'][2]))
            except: pass

        if '{{IP_HullF}}' in text:
            try:    text = text.replace('{{IP_HullF}}',str(self.myTargetedTankDescr['hullArmor'][0]))
            except: pass
        if '{{IP_HullS}}' in text:
            try:    text = text.replace('{{IP_HullS}}',str(self.myTargetedTankDescr['hullArmor'][1]))
            except: pass
        if '{{IP_HullR}}' in text:
            try:    text = text.replace('{{IP_HullR}}',str(self.myTargetedTankDescr['hullArmor'][2]))
            except: pass

        if '{{IP_TurretF}}' in text:
            try:    text = text.replace('{{IP_TurretF}}',str(self.myTargetedTankDescr['turretArmor'][0]))
            except: pass
        if '{{IP_TurretS}}' in text:
            try:    text = text.replace('{{IP_TurretS}}',str(self.myTargetedTankDescr['turretArmor'][1]))
            except: pass
        if '{{IP_TurretR}}' in text:
            try:    text = text.replace('{{IP_TurretR}}',str(self.myTargetedTankDescr['turretArmor'][2]))
            except: pass
        
        return text, attackerAmmo

    def checkColor(self, Ccolor, Type = '', attackerAmmo = 'credit' , attackReasonID = 0, weight = 'even'):
        if Ccolor == 'diff':
            tempColor = '#FFFFFF'
            for z1 in xrange(0,len(self.myColors)):
                if self.myColors[z1]['type'] == 'diff':
                    if self.myCurrDamage < 0:
                        for z2 in xrange(0,len(self.myColors)):
                            if self.myColors[z2]['value'] == 'less': return self.hexToRgba(self.myColors[z2]['color'])
                    if self.myCurrDamage == 0:
                        for z2 in xrange(0,len(self.myColors)):
                            if self.myColors[z2]['value'] == 'same': return self.hexToRgba(self.myColors[z2]['color'])
                    if self.myCurrDamage > 0:
                        for z2 in xrange(0,len(self.myColors)):
                            if self.myColors[z2]['value'] == 'more': return self.hexToRgba(self.myColors[z2]['color'])
            return self.hexToRgba(tempColor)
        if Ccolor == 'WN8':
            tempColor = '#000000'
            for z in xrange(0,len(self.myColors)):
                if self.myColors[z]['type'] == 'WN8':
                    if self.myWN8 >= self.myColors[z]['value']:
                        tempColor = self.myColors[z]['color']
            return self.hexToRgba(tempColor)     
        if Ccolor == 'EFF':
            tempColor = '#FFFFFF'
            for z in xrange(0,len(self.myColors)):
                if self.myColors[z]['type'] == 'EFF':
                    if self.myEFF >= self.myColors[z]['value']:
                        tempColor = self.myColors[z]['color']
            return self.hexToRgba(tempColor)        
        if Ccolor == 'hit':
            tempColor = '#FFFFFF'
            for z in xrange(0,len(self.myColors)):
                if self.myColors[z]['type'] == 'hit':
                    if self.myColors[z]['value'] == Type:
                        return self.hexToRgba(self.myColors[z]['color'])
            return self.hexToRgba(tempColor)        
        if Ccolor == 'ammo':
            tempColor = '#FFFFFF'
            for z in xrange(0,len(self.myColors)):
                if self.myColors[z]['type'] == 'ammo':
                    if self.myColors[z]['value'] == attackerAmmo:
                        return self.hexToRgba(self.myColors[z]['color'])
            return self.hexToRgba(tempColor)        
        if Ccolor == 'damage':
            tempColor = '#FFFFFF'
            for z in xrange(0,len(self.myColors)):
                if self.myColors[z]['type'] == 'damage':
                    if self.myColors[z]['value'] == ATTACK_REASONS[attackReasonID]:
                        return self.hexToRgba(self.myColors[z]['color'])
            return self.hexToRgba(tempColor)        
        if Ccolor == 'weight':
            tempColor = '#FFFFFF'
            for z in xrange(0,len(self.myColors)):
                if self.myColors[z]['type'] == 'weight':
                    if self.myColors[z]['value'] == weight:
                        return self.hexToRgba(self.myColors[z]['color'])
            return self.hexToRgba(tempColor)        
        return self.hexToRgba(Ccolor)

    def getShellPrice(self, nationID, shellID):
        price = {}
        xmlPath = ITEM_DEFS_PATH + 'vehicles/' + nations.NAMES[nationID] + '/components/shells.xml'
        for name, subsection in ResMgr.openSection(xmlPath).items():
            if name != 'icons':
                xmlCtx = (None, xmlPath + '/' + name)
                if _xml.readInt(xmlCtx, subsection, 'id', 0, 65535) == shellID:
                    price = _xml.readPrice(xmlCtx, subsection, 'price')
                    break
        ResMgr.purge(xmlPath, True)
        return price

    def updateTotalDamage(self, battleID, myDamage, newHealth, attackerID, attackReasonID):
        self.updateHitLog(battleID, myDamage, newHealth, attackReasonID)        
        if BigWorld.player().arena.vehicles.get(battleID)['team'] != BigWorld.player().team:
            self.myTotalDamage += myDamage
            timeNow = time.time() - 5
            if timeNow > self.myLastTime2:
                self.myLastTime2 = time.time()
                self.myIsNewDamage = True
            else:
                self.myIsNewDamage = False
            if attackReasonID == 0: self.myHits += 1
            self.myLastDamage = myDamage
        self.updateEFF()

    def updateEFF(self):
        if self.myConfigOK != True: print 'MultiHitLog error in json file.'
        player = BigWorld.player()     
        ownID = BigWorld.player().playerVehicleID
        current = player.arena.vehicles.get(ownID)
        #VehicleFullName = current['vehicleType'].type.userString
        self.myFrags = len(BigWorld.player()._PlayerAvatar__frags)
        self.myExpDamage = 0
        self.myWN8 = 0
        self.myEFF = 0
        self.myXWN8 = 0
        self.myError = 'Error'
        self.myXEFF = 0
        self.myAvgDamage = 0
        self.myCurrDamage = 0
        
        keys = len(self.myTankExpDArray)
        for xx in xrange(1,keys):            
            if self.myTypeDescriptor != 0:
                if self.myTypeDescriptor.type.id[0] == (int(self.myTankExpDArray[xx][9]) >> 4 & 15) and self.myTypeDescriptor.type.id[1] == (int(self.myTankExpDArray[xx][9]) >> 8 & 65535):
                    self.myExpDamage = self.myTankExpDArray[xx][2]
                    rSPOT = self.myTankExpDArray[xx][3]
                    rFRAG = self.myTankExpDArray[xx][1]
                    rDEF = self.myTankExpDArray[xx][4]
                    rWIN = self.myTankExpDArray[xx][5]
                    rTIER = self.myTankExpDArray[xx][6]
                    self.myWN8, self.myEFF, self.myXWN8, self.myXEFF = self.calcEFI(self.myTotalDamage, self.myExpDamage, rSPOT, rFRAG, self.myFrags, rDEF, rWIN, rTIER)
                    self.myError = 'OK'
                    break
            else: self.myError = 'NotYet'
        
        if self.myError == 'Error':
            print 'MultiHitLog error: no data for current tank'

        self.myCurrDamage = float(self.myTotalDamage) - float(self.myExpDamage)
        if self.myHits >0:
            self.myAvgDamage = float(self.myTotalDamage) / float(self.myHits)
        else:
            self.myAvgDamage = 0
        for z in xrange(0,len(self.myWindowKeyList)):    
            for z1 in xrange(0,len(self.myConfigKey[z])):
                lineNr = self.checkLine(self.myConfigKey[z][z1]['LineType'])
                if lineNr != 4 and lineNr != 6 and lineNr != 7:
                    for z2 in xrange(0,len(self.myLineTypesOrig[lineNr])):
                        unIdTxt = '1' + str(z)+str(z1)+str(z2)
                        unId = int(unIdTxt) 
                        self.myWindowLabelsKey[unId].text, ammo =  self.checkMacros(self.myLineTypesOrig[lineNr][z2]['text'],0,-1,0)
                        self.myWindowLabelsKey[unId].colour =  self.checkColor(self.myLineTypesOrig[lineNr][z2]['color'],'',ammo,0)

    def updateHitLog(self, battleID = 0, myDamage = 0, newHealth = 0, attackReasonID = 0):
        self.myHitLogSwitch = True
        pozz = self.myHitLogCounter
        found = False
        self.myHitLogPozz = 0
        if self.myConfig.get('groupHitLog') == 'True':
            for z in xrange(0,pozz):
                if self.myHitLogList[z]['Name'] == BigWorld.player().arena.vehicles.get(battleID)['name']: #vehicle.shortUserName
                    self.myHitLogList[z]['Hits'] += 1 
                    self.myHitLogList[z]['TotalDamage'] += myDamage
                    self.myHitLogList[z]['LastDamage'] = myDamage
                    self.myHitLogList[z]['Attack'] = attackReasonID
                    if newHealth <= 0:
                        self.myHitLogList[z]['Killed'] = 'True'
                    found = True    
        if found == False:                
            for z in xrange(1,self.myTankCounterEnemy):
                if self.myTankListEnemy[z]['playerName']:
                    if self.myTankListEnemy[z]['playerName'] == BigWorld.player().arena.vehicles.get(battleID)['name']:
                        self.myHitLogList[pozz]['Hits'] = 1 
                        self.myHitLogList[pozz]['TotalDamage'] = myDamage
                        self.myHitLogList[pozz]['LastDamage'] = myDamage
                        self.myHitLogList[pozz]['Tank'] = self.myTankListEnemy[z]['tankName']
                        self.myHitLogList[pozz]['Name'] = self.myTankListEnemy[z]['playerName']
                        self.myHitLogList[pozz]['Attack'] = attackReasonID
                        self.myHitLogList[pozz]['Ally'] = 'False'
                        if newHealth <= 0:
                            self.myHitLogList[pozz]['Killed'] = 'True'
                        else:
                            self.myHitLogList[pozz]['Killed'] = 'False'
                        self.myHitLogCounter += 1
                        break
            for z in xrange(1,self.myTankCounterAlly):
                if self.myTankListAlly[z]['playerName']:
                    if self.myTankListAlly[z]['playerName'] == BigWorld.player().arena.vehicles.get(battleID)['name']:
                        self.myHitLogList[pozz]['Hits'] = 1 
                        self.myHitLogList[pozz]['TotalDamage'] = myDamage
                        self.myHitLogList[pozz]['LastDamage'] = myDamage
                        self.myHitLogList[pozz]['Tank'] = self.myTankListAlly[z]['tankName']
                        self.myHitLogList[pozz]['Name'] = self.myTankListAlly[z]['playerName']
                        self.myHitLogList[pozz]['Attack'] = attackReasonID
                        self.myHitLogList[pozz]['Ally'] = 'True'
                        self.myHitLogList[pozz]['Killed'] = 'False'
                        if newHealth <= 0:
                            self.myHitLogList[pozz]['Killed'] = 'True'
                        else:
                            self.myHitLogList[pozz]['Killed'] = 'False'
                        self.myHitLogCounter += 1
                        break                    
        for z in xrange(0,len(self.myWindowKeyList)):  
            hitLogPoz = self.myHitLogCounter
            for z1 in xrange(0,len(self.myConfigKey[z])):                                        
                lineNr = self.checkLine(self.myConfigKey[z][z1]['LineType'])
                if lineNr == 4:
                    hitLogPoz -= 1
                    for z2 in xrange(0,len(self.myLineTypesOrig[lineNr])):
                        unIdTxt = '1' + str(z)+str(z1)+str(z2)
                        unId = int(unIdTxt)
                        HitLogWidth = self.myLineTypesOrig[lineNr][z2]['width']
                        text = str(self.myLineTypesOrig[lineNr][z2]['text'])
                        self.myWindowLabelsKey[unId].text, ammo =  self.checkMacros(text,battleID,hitLogPoz,attackReasonID,0,myDamage,0,0,HitLogWidth)
                        self.myWindowLabelsKey[unId].colour = self.checkColor(self.myLineTypesOrig[lineNr][z2]['color'],'',ammo,attackReasonID)
        self.updateEFF()

    def updateDamageLog(self, battleID, attackerID, attackReasonID, Damage, effectsIndex, myHealth, when, place):                
        player = BigWorld.player()  
        current = player.arena.vehicles.get(battleID)
        attacker = player.arena.vehicles.get(attackerID)    #Attacker vehicle
        currentVehicleID = player.playerVehicleID           #My vehicle
        ownID = BigWorld.player().playerVehicleID
        ownVehicle = player.arena.vehicles.get(ownID) 
        change = False
        
        if self.myIsItLast <> 2 and myHealth > 0 and self.myLastAttacker == attackerID and when <= (self.myLastTime + 0.2) and attackerID != currentVehicleID and attackReasonID == 0:
            if self.myDamageLineCounter >= 1:
                self.myDamageLineCounter -= 1
            else:
                self.myDamageLineCounter = 0
            if self.myBounce > 0:
                self.myBounce -= 1
            else:
                self.myBounce = 0
            place = self.myCritic            
        if self.myIsItLast <> 2 and myHealth > 0:
            self.myLastTime = when
            self.myLastAttacker = attackerID 
            if battleID == currentVehicleID and player.team != attacker['team'] and Damage > 0 and self.myConfig.get('ShowPen') == 'True': ################### PENETRATION
                self.myDamageLogSwitch = True
                if attackReasonID == 0: self.myPen += 1
                self.myDamageLineCounter += 1
                Type = 'pen'              
                self.myTotalDamageReceived += Damage
                self.myDamageLogList[self.myDamageLineCounter]['battleID'] = battleID
                self.myDamageLogList[self.myDamageLineCounter]['attackReasonID'] = attackReasonID
                self.myDamageLogList[self.myDamageLineCounter]['attackerID'] = attackerID
                self.myDamageLogList[self.myDamageLineCounter]['Damage'] = Damage
                self.myDamageLogList[self.myDamageLineCounter]['effectsIndex'] = effectsIndex
                self.myDamageLogList[self.myDamageLineCounter]['myHealth'] = myHealth
                self.myDamageLogList[self.myDamageLineCounter]['place'] = place
                self.myDamageLogList[self.myDamageLineCounter]['type'] = Type
                self.myDamageLogList[self.myDamageLineCounter]['Nr'] = self.myDamageLineCounter
                change = True
                
            elif battleID == currentVehicleID and player.team != attacker['team'] and Damage <= 0 and self.myConfig.get('ShowBounce') == 'True': ################### BOUNCE
                self.myDamageLogSwitch = True
                self.myBounce += 1
                self.myDamageLineCounter += 1
                self.myCritic = place
                Type = 'bounce'
                self.myDamageLogList[self.myDamageLineCounter]['battleID'] = battleID
                self.myDamageLogList[self.myDamageLineCounter]['attackReasonID'] = attackReasonID
                self.myDamageLogList[self.myDamageLineCounter]['attackerID'] = attackerID
                self.myDamageLogList[self.myDamageLineCounter]['Damage'] = Damage
                self.myDamageLogList[self.myDamageLineCounter]['effectsIndex'] = effectsIndex
                self.myDamageLogList[self.myDamageLineCounter]['myHealth'] = myHealth
                self.myDamageLogList[self.myDamageLineCounter]['place'] = place
                self.myDamageLogList[self.myDamageLineCounter]['type'] = Type
                self.myDamageLogList[self.myDamageLineCounter]['Nr'] = self.myDamageLineCounter
                change = True
                
            elif battleID == currentVehicleID and player.team == attacker['team'] and self.myConfig.get('ShowAlly') == 'True':         ################### FRIENDLY FIRE
                self.myDamageLogSwitch = True
                if attackReasonID == 0 and Damage > 0: self.myAlly += 1
                self.myDamageLineCounter += 1
                Type = 'ally'
                self.myDamageLogList[self.myDamageLineCounter]['battleID'] = battleID
                self.myDamageLogList[self.myDamageLineCounter]['attackReasonID'] = attackReasonID
                self.myDamageLogList[self.myDamageLineCounter]['attackerID'] = attackerID
                self.myDamageLogList[self.myDamageLineCounter]['Damage'] = Damage
                self.myDamageLogList[self.myDamageLineCounter]['effectsIndex'] = effectsIndex
                self.myDamageLogList[self.myDamageLineCounter]['myHealth'] = myHealth
                self.myDamageLogList[self.myDamageLineCounter]['place'] = place
                self.myDamageLogList[self.myDamageLineCounter]['type'] = Type
                self.myDamageLogList[self.myDamageLineCounter]['Nr'] = self.myDamageLineCounter
                change = True                
                self.myTotalDamageReceived += Damage
                
                if self.myConfig.get('AnnounceAllyDamage') == 'True' and currentVehicleID != attackerID and Damage > 0 and Damage >= self.myConfig.get('MinimumAllyDamage'):
                    text = self.myConfig.get('AllyDamageMessage') 
                    text, ammo = self.checkMacros(text,battleID,-1,attackReasonID,attackerID,Damage,effectsIndex,place,0)
                    player.broadcast(chatManager.battleTeamChannelID, text.encode('utf8', 'xmlcharrefreplace'))
                                    
                if self.myConfig.get('AnnounceAllyDamageOnlyMe') == 'True' and currentVehicleID != attackerID and Damage > 0:
                    text = self.myConfig.get('AllyDamageMessageForYou') 
                    text, ammo = self.checkMacros(text,battleID,-1,attackReasonID,attackerID,Damage,effectsIndex,place,0)
                    MessengerEntry.g_instance.gui.addClientMessage(text)
        if self.myIsItLast == 1:
            self.myIsItLast = 2

        if change == True:
            for z in xrange(0,len(self.myWindowKeyList)):
                DamageLogPoz = self.myDamageLineCounter                
                for z1 in xrange(0,len(self.myConfigKey[z])):
                    lineNr = self.checkLine(self.myConfigKey[z][z1]['LineType'])
                    if lineNr == 6:                        
                        for z2 in xrange(0,len(self.myLineTypesOrig[lineNr])):
                            unIdTxt = '1' + str(z)+str(z1)+str(z2)
                            unId = int(unIdTxt)
                            if DamageLogPoz < 1:
                                self.myWindowLabelsKey[unId].text = ''
                            else:                                
                                DamageLogWidth = self.myLineTypesOrig[lineNr][z2]['width']
                                text = str(self.myLineTypesOrig[lineNr][z2]['text'])
                                currBattleID = self.myDamageLogList[DamageLogPoz]['battleID'] 
                                currAttackReasonID = self.myDamageLogList[DamageLogPoz]['attackReasonID'] 
                                currAttackerID = self.myDamageLogList[DamageLogPoz]['attackerID']            
                                currDamage = self.myDamageLogList[DamageLogPoz]['Damage']
                                currEffectsIndex = self.myDamageLogList[DamageLogPoz]['effectsIndex']
                                currPlace = self.myDamageLogList[DamageLogPoz]['place']
                                currType = self.myDamageLogList[DamageLogPoz]['type']                            
                                damageNr = self.myDamageLogList[DamageLogPoz]['Nr']
                                self.myWindowLabelsKey[unId].text, ammo = self.checkMacros(text,currBattleID,-1,currAttackReasonID,currAttackerID,currDamage,currEffectsIndex,currPlace,DamageLogWidth,damageNr)
                                self.myWindowLabelsKey[unId].colour = self.checkColor(self.myLineTypesOrig[lineNr][z2]['color'],currType,ammo,currAttackReasonID)
                        DamageLogPoz -= 1
        self.updateEFF()

    def updateHPLeft(self, battleID):
        counter = 1
        self.myTankListEnemySorted.clear()
        for z in xrange(1,self.myTankCounterEnemy):
            try: self.myTankListEnemy[z]['currentHealth'] = BigWorld.entity(self.myTankListEnemy[z]['battleID']).health
            except: pass
            if self.myTankListEnemy[z]['currentHealth'] > 0:
                self.myTankListEnemySorted[counter]['currentHealth'] = self.myTankListEnemy[z]['currentHealth']
                self.myTankListEnemySorted[counter]['tankName'] = self.myTankListEnemy[z]['tankName'] 
                self.myTankListEnemySorted[counter]['playerName'] = self.myTankListEnemy[z]['playerName']
                self.myTankListEnemySorted[counter]['team'] = self.myTankListEnemy[z]['team'] 
                self.myTankListEnemySorted[counter]['maxHealth'] = self.myTankListEnemy[z]['maxHealth'] 
                self.myTankListEnemySorted[counter]['battleID'] = self.myTankListEnemy[z]['battleID']
                counter += 1
        for z in xrange(0,len(self.myWindowKeyList)):  
            HPLeftPoz = 1
            for z1 in xrange(0,len(self.myConfigKey[z])):                                        
                lineNr = self.checkLine(self.myConfigKey[z][z1]['LineType'])
                if lineNr == 7:
                    HPLeftPoz += 1
                    if HPLeftPoz == self.myTankCounterEnemy: HPLeftPoz  = self.myTankCounterEnemy
                    for z2 in xrange(0,len(self.myLineTypesOrig[lineNr])):
                        unIdTxt = '1' + str(z)+str(z1)+str(z2)
                        unId = int(unIdTxt)
                        HPLeftWidth = self.myLineTypesOrig[lineNr][z2]['width']
                        text = str(self.myLineTypesOrig[lineNr][z2]['text'])
                        self.myWindowLabelsKey[unId].text, ammo =  self.checkMacros(text,0,HPLeftPoz,0,0,0,0,0,HPLeftWidth)
                        self.myWindowLabelsKey[unId].colour = self.checkColor(self.myLineTypesOrig[lineNr][z2]['color'],'',ammo,0)
        self.updateEFF()

    def updateInfoPanel(self):

        timePast = int(self.myIPtimer - time.time())
        secToReset = self.myConfig.get('timeToShowOwnInfo')
        if not BigWorld.target() and timePast < secToReset:
            try:
                player = BigWorld.player()
                target = player.getVehicleAttached()
            except:
                pass

        if BigWorld.target():
            self.myIPtimer = time.time() 
            self.myInfoPanelSwitch = True
            player = BigWorld.player()
            target = BigWorld.target()
            
        try:
            typeDescr = target.typeDescriptor
            vTypeDescr = player.vehicleTypeDescriptor
            self.myTargetedTankDescr['TankName'] = typeDescr.type.userString
            self.myTargetedTankDescr['hullArmor'] = [int(typeDescr.hull['primaryArmor'][0]), int(typeDescr.hull['primaryArmor'][1]), int(typeDescr.hull['primaryArmor'][2])]
            self.myTargetedTankDescr['turretArmor'] = [int(typeDescr.turret['primaryArmor'][0]), int(typeDescr.turret['primaryArmor'][1]), int(typeDescr.turret['primaryArmor'][2])]
            self.myTargetedTankDescr['gunName'] = typeDescr.gun['shortUserString']                       
            loader_skill = 132 
            other_bonus = 0.9
            self.myTargetedTankDescr['ReloadTime'] = typeDescr.gun['reloadTime'] * 0.875 / (0.00375 * loader_skill + 0.5) * other_bonus
            self.myTargetedTankDescr['ViewRange'] = int(typeDescr.turret['circularVisionRadius'])
            self.myTargetedTankDescr['pWeight'] = int(round(vTypeDescr._VehicleDescr__computeWeight()[0] / 1000))
            self.myTargetedTankDescr['vWeight'] = int(round(typeDescr._VehicleDescr__computeWeight()[0] / 1000))
            
            z = 0
            for element in typeDescr.gun['shots']:
                self.myTargetedTankDescr['shellDamage'][z] = int(element['shell']['damage'][0])
                z += 1
                
            z = 0
            for element in typeDescr.gun['shots']:
                self.myTargetedTankDescr['shellPower'][z] = int(element['piercingPower'][0])
                z += 1
                
            z = 0
            for element in typeDescr.gun['shots']:
                if element['shell']['kind'] == 'ARMOR_PIERCING':
                    self.myTargetedTankDescr['shellType'][z] = element['shell']['kind'].replace('ARMOR_PIERCING', 'AP')
                elif element['shell']['kind'] == 'HIGH_EXPLOSIVE':
                    self.myTargetedTankDescr['shellType'][z] = element['shell']['kind'].replace('HIGH_EXPLOSIVE', 'HE')
                elif element['shell']['kind'] == 'ARMOR_PIERCING_CR':
                    self.myTargetedTankDescr['shellType'][z] = element['shell']['kind'].replace('ARMOR_PIERCING_CR', 'CR')
                else:
                    self.myTargetedTankDescr['shellType'][z] = element['shell']['kind'].replace('HOLLOW_CHARGE', 'HC')
                z += 1
        except:
            pass
        
        weightDiff = 'same'
        for z in xrange(0,len(self.myWindowKeyList)):    
            for z1 in xrange(0,len(self.myConfigKey[z])):
                lineNr = self.checkLine(self.myConfigKey[z][z1]['LineType'])
                if lineNr != 4 and lineNr != 6 and lineNr != 7:
                    for z2 in xrange(0,len(self.myLineTypesOrig[lineNr])):
                        unIdTxt = '1' + str(z)+str(z1)+str(z2)
                        unId = int(unIdTxt)
                        width = self.myLineTypesOrig[lineNr][z2]['width']
                        if self.myLineTypesOrig[lineNr][z2]['color'] == 'weight':         
                            pWeight = self.myTargetedTankDescr.get('pWeight')
                            vWeight = self.myTargetedTankDescr.get('vWeight')
                            weightDiff = 'same'
                            if int(pWeight or 0) < int(vWeight or 0):
                                weightDiff = 'more'
                            elif int(pWeight or 0) > int(vWeight or 0):
                                weightDiff = 'less'
                        self.myWindowLabelsKey[unId].text, ammo = self.checkMacros(self.myLineTypesOrig[lineNr][z2]['text'],0,-1,0,0,0,0,0,width)
                        self.myWindowLabelsKey[unId].colour =  self.checkColor(self.myLineTypesOrig[lineNr][z2]['color'],'',ammo,0,weightDiff)

    def checkLine(self, lineType):
        return int(lineType[4:])


old_PlayerAvatar_setVisibleGUI = PlayerAvatar._PlayerAvatar__setVisibleGUI


def new_PlayerAvatar_setVisibleGUI(self, bool):
    old_PlayerAvatar_setVisibleGUI(self, bool)
    HitLog.setVisible(bool)

PlayerAvatar._PlayerAvatar__setVisibleGUI = new_PlayerAvatar_setVisibleGUI
old_Battle_afterCreate = Battle.afterCreate


def new_Battle_afterCreate(self):
    old_Battle_afterCreate(self)
    HitLog.createWindows()
    HitLog.createLabels()
    guiKeyMonitor()
    HitLog.updateEFF()

Battle.afterCreate = new_Battle_afterCreate
old_Battle_beforeDelete = Battle.beforeDelete


def new_beforeDelete(self):
    old_Battle_beforeDelete(self)
    HitLog.resetData()
    HitLog.deleteWindow()    
Battle.beforeDelete = new_beforeDelete      
old_Vehicle_onEnterWorld = Vehicle.onEnterWorld


def new_Vehicle_onEnterWorld(self, prereqs):
    old_Vehicle_onEnterWorld(self, prereqs)
    player = BigWorld.player()
    __vID = BigWorld.player().playerVehicleID
    vehicle = BigWorld.entity(__vID)
    typeDescriptor = vehicles.VehicleDescr(compactDescr=self.publicInfo.compDescr)
    for key, vehicle in player.arena.vehicles.iteritems():
        if vehicle['name'] == self.publicInfo.name:
            HitLog.myBattleID = key
            HitLog.myTankListDescr[key]['currentHealth'] = BigWorld.entity(key).health
            exist = False
            if player.team == BigWorld.player().arena.vehicles.get(key)['team']:
                z = HitLog.myTankCounterAlly
                for y in xrange(0,z):
                    if HitLog.myTankListAlly[y]:
                        if HitLog.myTankListAlly[y]['battleID'] == key:
                            exist = True
                            HitLog.myTankListAlly[y]['currentHealth'] = BigWorld.entity(key).health
                if exist == False:    
                    HitLog.myTankListAlly[z]['tankName'] = typeDescriptor.type.shortUserString
                    HitLog.myTankListAlly[z]['playerName'] = BigWorld.player().arena.vehicles.get(key)['name']
                    HitLog.myTankListAlly[z]['team'] = BigWorld.player().arena.vehicles.get(key)['team'] 
                    HitLog.myTankListAlly[z]['maxHealth'] = typeDescriptor.maxHealth
                    HitLog.myTankListAlly[z]['currentHealth'] = BigWorld.entity(key).health
                    HitLog.myTankListAlly[z]['battleID'] = key
                    HitLog.myTankCounterAlly += 1                
            if player.team != BigWorld.player().arena.vehicles.get(key)['team']:
                z = HitLog.myTankCounterEnemy
                for y in xrange(0,z):
                    if HitLog.myTankListEnemy[y]:
                        if HitLog.myTankListEnemy[y]['battleID'] == key:
                            exist = True
                            HitLog.myTankListEnemy[y]['currentHealth'] = BigWorld.entity(key).health
                if exist == False:
                    HitLog.myTankListEnemy[z]['tankName'] = typeDescriptor.type.shortUserString
                    HitLog.myTankListEnemy[z]['playerName'] = BigWorld.player().arena.vehicles.get(key)['name']
                    HitLog.myTankListEnemy[z]['team'] = BigWorld.player().arena.vehicles.get(key)['team'] 
                    HitLog.myTankListEnemy[z]['maxHealth'] = typeDescriptor.maxHealth
                    HitLog.myTankListEnemy[z]['currentHealth'] = BigWorld.entity(key).health                
                    HitLog.myTankListEnemy[z]['battleID'] = key               
                    HitLog.myTankCounterEnemy += 1
            HitLog.updateHPLeft(key)
            if key == __vID:
                HitLog.PassTypeDescr(typeDescriptor)
            break
Vehicle.onEnterWorld = new_Vehicle_onEnterWorld
old_Vehicle_showDamageFromShot = Vehicle.showDamageFromShot


def new_Vehicle_showDamageFromShot(self, attackerID, points, effectsIndex):
    old_Vehicle_showDamageFromShot(self, attackerID, points, effectsIndex)

    player = BigWorld.player()
    place = ''
    for battleID, vehicle in player.arena.vehicles.iteritems():
        if vehicle['name'] == self.publicInfo.name:
            effectsDescr = vehicles.g_cache.shotEffects[effectsIndex]
            maxHitEffectCode, decodedPoints = DamageFromShotDecoder.decodeHitPoints(points, HitLog.myTypeDescriptor)
            hasPiercedHit = DamageFromShotDecoder.hasDamaged(maxHitEffectCode)
            HitLog.myHitType = effectsIndex            
            #print str(effectsDescr)
            #print str(HIT_EFFECT[maxHitEffectCode])
            #print str(decodedPoints[0][0])
            #print str(decodedPoints[0][2])
            #print str(hasPiercedHit)
            #print str(effectsIndex)
            if battleID == BigWorld.player().playerVehicleID:
                if decodedPoints[0][2]:
                    if decodedPoints[0][2] == 'armorCriticalHit':
                        place = str(decodedPoints[0][0])
                HitLog.updateDamageLog(battleID, attackerID, 0, 0, effectsIndex, 9999, time.time(), place)
            HitLog.updateHPLeft(battleID)
            break

Vehicle.showDamageFromShot = new_Vehicle_showDamageFromShot
old_Vehicle_onHealthChanged = Vehicle.onHealthChanged


def new_Vehicle_onHealthChanged(self, newHealth, attackerID, attackReasonID):
    old_Vehicle_onHealthChanged(self, newHealth, attackerID, attackReasonID)
    myDamage = 0
    myHealth = 9999
    player = BigWorld.player()
    for battleID, vehicle in player.arena.vehicles.iteritems():
        if vehicle['name'] == self.publicInfo.name:
            if battleID == BigWorld.player().playerVehicleID:
                myHealth = HitLog.myTankListDescr[battleID]['currentHealth']
                if newHealth <= 0 and HitLog.myIsItLast == 0:
                    HitLog.myIsItLast = 1
            if 'currentHealth' in HitLog.myTankListDescr[battleID]:
                myDamage = HitLog.myTankListDescr[battleID]['currentHealth'] - newHealth
                HitLog.myTankListDescr[battleID]['currentHealth'] = newHealth
                if BigWorld.player().playerVehicleID == attackerID:
                    HitLog.updateTotalDamage(battleID, myDamage, newHealth, attackerID, attackReasonID)
            HitLog.updateDamageLog(battleID, attackerID, attackReasonID, myDamage, HitLog.myHitType, myHealth, time.time(), '')
            HitLog.updateHPLeft(battleID)

Vehicle.onHealthChanged = new_Vehicle_onHealthChanged


def guiKeyMonitor():
    if BigWorld.isKeyDown(Keys.KEY_SPACE):
        HitLog.keyPressed('KEY_SPACE')
    elif BigWorld.isKeyDown(Keys.KEY_LSHIFT):
        HitLog.keyPressed('KEY_LSHIFT')
    elif BigWorld.isKeyDown(Keys.KEY_LALT):
        HitLog.keyPressed('KEY_LALT')
    elif BigWorld.isKeyDown(Keys.KEY_CAPSLOCK):
        HitLog.keyPressed('KEY_CAPSLOCK')
    elif BigWorld.isKeyDown(Keys.KEY_LCONTROL):
        HitLog.keyPressed('KEY_LCONTROL')
    elif BigWorld.isKeyDown(Keys.KEY_B):
        HitLog.keyPressed('KEY_B')
    elif BigWorld.isKeyDown(Keys.KEY_C):
        HitLog.keyPressed('KEY_C')
    elif BigWorld.isKeyDown(Keys.KEY_E):
        HitLog.keyPressed('KEY_E')
    elif BigWorld.isKeyDown(Keys.KEY_F):
        HitLog.keyPressed('KEY_F')
    elif BigWorld.isKeyDown(Keys.KEY_G):
        HitLog.keyPressed('KEY_G')
    elif BigWorld.isKeyDown(Keys.KEY_H):
        HitLog.keyPressed('KEY_H')
    elif BigWorld.isKeyDown(Keys.KEY_I):
        HitLog.keyPressed('KEY_I')
    elif BigWorld.isKeyDown(Keys.KEY_J):
        HitLog.keyPressed('KEY_J')
    elif BigWorld.isKeyDown(Keys.KEY_K):
        HitLog.keyPressed('KEY_K')
    elif BigWorld.isKeyDown(Keys.KEY_L):
        HitLog.keyPressed('KEY_L')
    elif BigWorld.isKeyDown(Keys.KEY_M):
        HitLog.keyPressed('KEY_M')
    elif BigWorld.isKeyDown(Keys.KEY_N):
        HitLog.keyPressed('KEY_N')
    elif BigWorld.isKeyDown(Keys.KEY_O):
        HitLog.keyPressed('KEY_O')
    elif BigWorld.isKeyDown(Keys.KEY_P):
        HitLog.keyPressed('KEY_P')
    elif BigWorld.isKeyDown(Keys.KEY_Q):
        HitLog.keyPressed('KEY_Q')
    elif BigWorld.isKeyDown(Keys.KEY_R):
        HitLog.keyPressed('KEY_R')
    elif BigWorld.isKeyDown(Keys.KEY_T):
        HitLog.keyPressed('KEY_T')
    elif BigWorld.isKeyDown(Keys.KEY_U):
        HitLog.keyPressed('KEY_U')
    elif BigWorld.isKeyDown(Keys.KEY_V):
        HitLog.keyPressed('KEY_V')
    elif BigWorld.isKeyDown(Keys.KEY_X):
        HitLog.keyPressed('KEY_X')
    elif BigWorld.isKeyDown(Keys.KEY_Y):
        HitLog.keyPressed('KEY_Y')
    elif BigWorld.isKeyDown(Keys.KEY_Z):
        HitLog.keyPressed('KEY_Z')
    elif BigWorld.isKeyDown(Keys.KEY_1):
        HitLog.keyPressed('KEY_1')
    elif BigWorld.isKeyDown(Keys.KEY_2):
        HitLog.keyPressed('KEY_2')
    elif BigWorld.isKeyDown(Keys.KEY_3):
        HitLog.keyPressed('KEY_3')
    elif BigWorld.isKeyDown(Keys.KEY_4):
        HitLog.keyPressed('KEY_4')
    elif BigWorld.isKeyDown(Keys.KEY_5):
        HitLog.keyPressed('KEY_5')
    elif BigWorld.isKeyDown(Keys.KEY_6):
        HitLog.keyPressed('KEY_6')
    elif BigWorld.isKeyDown(Keys.KEY_7):
        HitLog.keyPressed('KEY_7')
    elif BigWorld.isKeyDown(Keys.KEY_8):
        HitLog.keyPressed('KEY_8')
    elif BigWorld.isKeyDown(Keys.KEY_9):
        HitLog.keyPressed('KEY_9')
    elif BigWorld.isKeyDown(Keys.KEY_0):
        HitLog.keyPressed('KEY_0')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD1):
        HitLog.keyPressed('KEY_NUMPAD1')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD2):
        HitLog.keyPressed('KEY_NUMPAD2')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD3):
        HitLog.keyPressed('KEY_NUMPAD3')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD4):
        HitLog.keyPressed('KEY_NUMPAD4')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD5):
        HitLog.keyPressed('KEY_NUMPAD5')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD6):
        HitLog.keyPressed('KEY_NUMPAD6')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD7):
        HitLog.keyPressed('KEY_NUMPAD7')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD8):
        HitLog.keyPressed('KEY_NUMPAD8')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD9):
        HitLog.keyPressed('KEY_NUMPAD9')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPAD0):
        HitLog.keyPressed('KEY_NUMPAD0')
    elif BigWorld.isKeyDown(Keys.KEY_NUMLOCK):
        HitLog.keyPressed('KEY_NUMLOCK')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPADCOMMA):
        HitLog.keyPressed('KEY_NUMPADCOMMA')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPADENTER):
        HitLog.keyPressed('KEY_NUMPADENTER')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPADEQUALS):
        HitLog.keyPressed('KEY_NUMPADEQUALS')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPADMINUS):
        HitLog.keyPressed('KEY_NUMPADMINUS')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPADPERIOD):
        HitLog.keyPressed('KEY_NUMPADPERIOD')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPADSLASH):
        HitLog.keyPressed('KEY_NUMPADSLASH')
    elif BigWorld.isKeyDown(Keys.KEY_NUMPADSTAR):
        HitLog.keyPressed('KEY_NUMPADSTAR')
    else:
        HitLog.keyPressed('NONE')
        HitLog.updateInfoPanel()
    BigWorld.callback(0.1, guiKeyMonitor)
    return

HitLog = MultiHitLog()




